1930E - 234 Wonderful Wonderful - CodeForces Solution


combinatorics math

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int mod=998244353,N=1e6+100,maxn=1e6;
int fl[N],nf[N];

int mi(int x,int t){
	int d=1;
	while(t){
		if(t%2) d=(ll)d*x%mod;
		x=(ll)x*x%mod;t/=2;
	}
	return d;
}
int ni(int x) {return mi(x,mod-2);}

int C(int n,int m){
	if(m<0||m>n) return 0;
	return (ll)fl[n]*nf[m]%mod*nf[n-m]%mod;
}

int main()
{
	
	fl[0]=1;for(int i=1;i<=maxn;i++) fl[i]=(ll)fl[i-1]*i%mod;
	nf[maxn]=ni(fl[maxn]);for(int i=maxn-1;i>=0;i--) nf[i]=(ll)nf[i+1]*(i+1)%mod;
	
	int T;scanf("%d",&T);
	while(T--){
		int n;scanf("%d",&n);
		
		for(int i=1;i<=(n-1)/2;i++){
			int Sum=1;
			for(int j=i*2;j<=n;j+=i*2)
				Sum=(Sum+C(n,j))%mod;
				
			for(int len=2;len<=n;len=len+i*2) Sum=(Sum-C(n-len+1,2*(i-1)+1)+mod)%mod;
			/*for(int j=1;j<=n;j++)
				for(int k=j;k<=n;k++)
					if((k-j+1+(i-1)*2)%(i*2)==0){
						int tmp=(ll)C(j-1,i-1)*C(n-k,i-1)%mod;
						C(j-1,j-i) n-k,i-1
						n-k+j-1,j-1
						n-len
						Sum=(Sum-tmp+mod)%mod;
					}*/
			printf("%d ",Sum);
		}
		printf("\n");
	}
	
	return 0;
}


Comments

Submit
0 Comments
More Questions

1671C - Dolce Vita
1669G - Fall Down
4D - Mysterious Present
1316B - String Modification
1204A - BowWow and the Timetable
508B - Anton and currency you all know
1672A - Log Chopping
300A - Array
48D - Permutations
677C - Vanya and Label
1583B - Omkar and Heavenly Tree
1703C - Cypher
1511C - Yet Another Card Deck
1698A - XOR Mixup
1702E - Split Into Two Sets
1703B - ICPC Balloons
1702F - Equate Multisets
1700A - Optimal Path
665C - Simple Strings
1708A - Difference Operations
1703E - Mirror Grid
1042A - Benches
1676B - Equal Candies
1705B - Mark the Dust Sweeper
1711A - Perfect Permutation
1701B - Permutation
1692A - Marathon
1066A - Vova and Train
169B - Replacing Digits
171D - Broken checker